/**
 * 上传信息管理初始化
 */
var UploadInfo = {
    id: "UploadInfoTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
UploadInfo.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: 'id', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '类型', field: 'type', visible: true, align: 'center', valign: 'middle'},
            {title: '被保险人姓名', field: 'insurerName', visible: true, align: 'center', valign: 'middle'},
            {title: '联系方式', field: 'contact', visible: true, align: 'center', valign: 'middle'},
            {title: '报案序号', field: 'reportNum', visible: true, align: 'center', valign: 'middle'},
            {title: '领取类型 （0：被保险人领取，1：为非被保险人领取', field: 'gainType', visible: true, align: 'center', valign: 'middle'},
            {title: '领款人', field: 'payee', visible: true, align: 'center', valign: 'middle'},
            {title: '开户行', field: 'bankName', visible: true, align: 'center', valign: 'middle'},
            {title: '银行账号', field: 'bankAccount', visible: true, align: 'center', valign: 'middle'},
            {title: '投保人证件类型', field: 'insurerCertificateType', visible: true, align: 'center', valign: 'middle'},
            {title: '领卡人证件类型', field: 'gainCertificateType', visible: true, align: 'center', valign: 'middle'},
            {title: '授权人类型', field: 'authoryPersonType', visible: true, align: 'center', valign: 'middle'},
            {title: '出险地点', field: 'incidentAddr', visible: true, align: 'center', valign: 'middle'},
            {title: '是否住院，1：是 ，0：否', field: 'isHospitalized', visible: true, align: 'center', valign: 'middle'},
            {title: '医院地址', field: 'hospitalAddr', visible: true, align: 'center', valign: 'middle'},
            {title: '是否车辆：1：是 ，0：否', field: 'isCar', visible: true, align: 'center', valign: 'middle'},
            {title: '状态 1：为有效，0为无效', field: 'state', visible: true, align: 'center', valign: 'middle'},
            {title: '', field: 'creater', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
UploadInfo.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        UploadInfo.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加上传信息
 */
UploadInfo.openAddUploadInfo = function () {
    var index = layer.open({
        type: 2,
        title: '添加上传信息',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/uploadInfo/uploadInfo_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看上传信息详情
 */
UploadInfo.openUploadInfoDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '上传信息详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/uploadInfo/uploadInfo_update/' + UploadInfo.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除上传信息
 */
UploadInfo.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/uploadInfo/delete", function (data) {
            Feng.success("删除成功!");
            UploadInfo.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("uploadInfoId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询上传信息列表
 */
UploadInfo.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    UploadInfo.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = UploadInfo.initColumn();
    var table = new BSTable(UploadInfo.id, "/uploadInfo/list", defaultColunms);
    table.setPaginationType("client");
    UploadInfo.table = table.init();
});
